
//int& Add(int x, int y)
//{
//	int z = x + y;
//	return z;
//}
//int main()
//{
//	int& ret1 = Add(1, 2);
//	int& ret2 = Add(3, 4);
//	return 0;
//}

//int getMax(int a, int b) 
//{
//    return (a > b) ? a : b;
//}
//
//int main()
//{
//    int max_val = getMax(1, 3);
//    cout << "max_val = "  << max_val << endl;
//    return 0;
//}
#include "f.h"


//#define GetMax(x, y) (x) > (y) ? (x) : (y)
//int main()
//{
//	int x = GetMax(1 + 3, 2 + 5);
//	cout << x << endl;
//	return 0;
//}
#include <vector>
#include <queue>

struct TreeNode 
{
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
    TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
};
vector<TreeNode*> LeavesNumber;

void dfs(TreeNode* root)
{
    if (root->left == nullptr && root->right == nullptr)
    {
        LeavesNumber.push_back(root);
        return;
    }
    if (root->left) dfs(root->left);
    if (root->right) dfs(root->right);

}
int sumOfLeftLeaves(TreeNode* root)
{
    queue<TreeNode*> q;
    vector<TreeNode*> v;

    q.push(root);
    while (!q.empty())
    {
        TreeNode* front = q.front();
        q.pop();
        v.push_back(front);
        if (front->left) q.push(front->left);
        if (front->right) q.push(front->right);
    }
    int ret = 0;
    for (int i = 0; i < LeavesNumber.size(); ++i)
    {
        for (int j = 0; j < v.size(); ++j)
        {
            if (v[j] == LeavesNumber[i])
            {
                int k = (j - 1) / 2;
                if ((k * 2 + 1) == j)
                {
                    ret += LeavesNumber[i]->val;
                }
            }
        }
    }
    return ret;
}
int main()
{
    TreeNode* root = new TreeNode(1);
    TreeNode* left = new TreeNode(2);
    root->left = left;
    sumOfLeftLeaves(root);
    return 0;
}